package com.lsh.payment.core.strategy.payment;


import com.lsh.payment.api.model.basevo.ExceptionStatus;
import com.lsh.payment.core.exception.BusinessException;
import com.lsh.payment.core.strategy.vo.base.BasePayResponse;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

import static com.lsh.payment.core.constant.BusinessConstant.STRATEGY_BEAN_NAME_PREFIX;


/**
 * 支付策略上下文
 * Project Name: lsh-payment
 *
 * @author peter
 * @date 16/10/30
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Component
public class PayStrategyContext {

    @Resource
    private Map<String, PayStrategy> strategies;

    /**
     * 调用对应支付平台组装支付请求报文
     *
     * @param payType
     * @param params
     * @return
     */
    public BasePayResponse generatePayParams(int payType, final Map<String, String> params) {
        PayStrategy<BasePayResponse> strategy = strategies.get(STRATEGY_BEAN_NAME_PREFIX + payType);
        if (strategy == null) {
            throw new BusinessException(ExceptionStatus.E2001002.getCode(), "payType 参数异常");
        }
        return strategy.generatePayParams(payType, params);
    }

}
